﻿using System.ComponentModel;
using System.Web.UI;

namespace Besture.CmsControl
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:DropDownList runat=server></{0}:DropDownList>")]
    public class DropDownList : System.Web.UI.WebControls.DropDownList
    {
        public DropDownList()
        {
            
        }

        [Bindable(true)]
        [DefaultValue("False")]
        [Localizable(true)]
        [Category("Action")]
        [Description("输入验证")]
        public bool Required
        {
            get
            {
                bool s = (bool)ViewState["Required"];
                //添加jquery.validate验证
                if (s)
                {
                    this.CssClass += " required";
                }
                return s;
            }
            set
            {
                if (value == null)
                {
                    value = false;
                }
                ViewState["Required"] = value;
            }
        }



        protected override void RenderContents(HtmlTextWriter output)
        {
        }

        protected override void Render(HtmlTextWriter writer)
        {
            //文本框必输情况对应图片
            var img = Required ? "<img src='/Admin/Themes/Images/indispensable.gif' align='absMiddle' />" : "<img src='/Admin/Themes/Images/dispensable.png' align='absMiddle' />";
            writer.Write(img);
            base.Render(writer);
        }
    }
}
